import { defineStore } from 'pinia';
import { reqMusic,reqMySongList, reqPlayList } from '../request/api';

export const useMusicStore = defineStore('music', {
	state: () => ({
		all_music: {},
		find_music: {},
		play_list:[],
		my_song_list: {
			topInfo: {
				imgUrl: '/src/assets/my_song_list_img/1.jpg',
				userName: 'test',
				name: '我喜欢的音乐',
				time: '2021-11-05 创建',
				addPlayNum: 722957,
				shareNum: 12854,
				commentNum: 14123
			},
			songListInfo: {
				songCount: 471,
				playCount: 60,
				songList: []
			}
		}
	}),
	getters:{
		play_list_map_table : ($state) => $state.play_list.map(item => (item as any).music.id)
	},
	actions: {
		async fetchMusic(id?:number) {
			if (id) {
				this.$state.find_music = await reqMusic(id);
			
			}

		},

		async fetchMySongList() {
			this.$state.my_song_list.songListInfo.songList = (await reqMySongList()) as any;
			
		},

		async fetchPlayList(id?:number){
			this.$state.play_list = (await reqPlayList(id)) as any;
		}

	}
});
